# An object displaying a card summary in the Card Viewer available cards area.
class_name CVListCardObject
extends HBoxContainer

var grid_card_object: CVGridCardObject
# A pointer back to the cardlibrary scene
var card_viewer

# The properties of the card, used for filtering
var card_properties: Dictionary
# The canonical card name of this card
var card_name: String

onready var _card_label:= $CardLabel
onready var _card_type:= $Type

func _ready() -> void:
	_card_label.preview_popup.focus_info.info_panel_scene = card_viewer.info_panel_scene
	_card_label.preview_popup.focus_info.setup()
	_card_label.custom_effects = card_viewer.custom_rich_text_effects


# This is used to prepare the values of this object
func setup(_card_name: String) -> void:
	card_properties = cfc.card_definitions[_card_name].duplicate()
	# We enable games to have autogenerated values on cards
	# If the defined property value is in the list specifying
	# values for autogeneration, then we send to the deckbuilder to discover
	# the value
	# The autogeneration function is in the deckbuilder, as it's easily
	# extendable by games
	for prop in card_properties:
		if card_properties[prop] in card_viewer.generation_keys:
			card_properties[prop] = card_viewer.generate_value(prop,card_properties)
	card_name = _card_name
	$Type.text = card_properties[CardConfig.SCENE_PROPERTY]
	_card_label.text = card_name


func setup_grid_card_object() -> void:
	if not grid_card_object:
		grid_card_object = card_viewer.grid_card_object_scene.instance()
		card_viewer._card_grid.add_child(grid_card_object)
		# warning-ignore:return_value_discarded
		grid_card_object.setup(card_name)
		grid_card_object.card_list_object = self
		grid_card_object.preview_popup.focus_info.info_panel_scene = card_viewer.info_panel_scene
		grid_card_object.preview_popup.focus_info.setup()


func set_visibility(value) -> void:
	visible = value
	if grid_card_object:
		grid_card_object.visible = value
